clear
use          "$gendatadir/us_predicted_differences.dta"
append using "$gendatadir/ca_predicted_differences.dta"
append using "$gendatadir/se_predicted_differences.dta"
append using "$gendatadir/uk_predicted_differences.dta"

*gen ctry = 1 if model_country == "USA"
*replace ctry = 2 if model_country == "Canada"
*replace ctry = 3 if model_country == "Sweden"
*replace ctry = 4 if model_country == "UK"

encode model_country, gen(ctry)
label variable ctry "country"

gen     model_num = 1 if model_name == "BartelsLogtenure"
replace model_num = 2 if model_name == "PreferredLow"
replace model_num = 3 if model_name == "PreferredMid"
replace model_num = 4 if model_name == "PreferredQ1Low"
replace model_num = 5 if model_name == "PreferredQ3Mid"

gen     model_num_u = model_num + .12
gen     model_num_l = model_num - .12

gen predicted_diff_t5_u = predicted_diff_t5_m + 1.65*predicted_diff_t5_se
gen predicted_diff_t5_l = predicted_diff_t5_m - 1.65*predicted_diff_t5_se

gen predicted_diff_mean_u = predicted_diff_mean_m + 1.65*predicted_diff_mean_se
gen predicted_diff_mean_l = predicted_diff_mean_m - 1.65*predicted_diff_mean_se

*graph twoway (rcap predicted_diff_t5_u predicted_diff_t5_l model_num) (scatter predicted_diff_t5_m model_num, yline(0)), by(ctry, legend(off) note("")) plotregion(margin(l+5 r+5)) scheme(s1mono) xtitle("") xlabel(1 "All" 2 "Low/M" 3 "Mid/M" 4 "Low/Q1" 5 "Mid/Q3")
*graph export "dboutput/predicted_diff_t5.pdf", replace
*window manage close graph

*graph twoway (rcap predicted_diff_mean_u predicted_diff_mean_l model_num if inlist(model_num, 1, 2, 3)) (scatter predicted_diff_mean_m model_num if inlist(model_num, 1, 2, 3), yline(0)), by(ctry, legend(off) note("")) plotregion(margin(l+10 r+10)) scheme(s1mono) xtitle("") xlabel(1 "All" 2 "Low/M" 3 "Mid/M")
*graph export "dboutput/predicted_diff_mean.pdf", replace
*window manage close graph

*graph twoway (rcap predicted_diff_t5_u predicted_diff_t5_l model_num_l) (scatter predicted_diff_t5_m model_num_l, yline(0)) (rcap predicted_diff_mean_u predicted_diff_mean_l model_num_u if inlist(model_num, 1, 2, 3)) (scatter predicted_diff_mean_m model_num_u if inlist(model_num, 1, 2, 3), yline(0)), by(ctry, legend(off) note("")) plotregion(margin(l+5 r+5)) scheme(s1mono) xtitle("") xlabel(1 "All" 2 "Low/M" 3 "Mid/M" 4 "Low/Q1" 5 "Mid/Q3") yscale(range(-.1 .15)) ylabel(-.1[.05].15)
*graph export "dboutput/predicted_diff_combi.pdf", replace
*window manage close graph

graph twoway (rcap predicted_diff_t5_u predicted_diff_t5_l model_num_l if inlist(model_num, 1, 2, 3)) (scatter predicted_diff_t5_m model_num_l if inlist(model_num, 1, 2, 3), yline(0) msymbol(O) mcolor(gs2)) (rcap predicted_diff_mean_u predicted_diff_mean_l model_num_u if inlist(model_num, 1, 2, 3)) (scatter predicted_diff_mean_m model_num_u if inlist(model_num, 1, 2, 3), msymbol(S) mcolor(gs8) yline(0)), by(ctry, legend(off) note("")) plotregion(margin(l+10 r+10)) scheme(s1mono) xtitle("") xlabel(1 "All" 2 "Low" 3 "Mid") yscale(range(-.08 .1)) ylabel(-.08[.02].1, angle(horizontal))
graph export "$imagedir/predicted_diff_combi.pdf", replace
window manage close graph
